﻿using System;
using System.Diagnostics;
using System.Linq;
using LINQPad.OpenAccess.Helpers;
using Telerik.OpenAccess.Metadata;

namespace LINQPad.OpenAccess.Metadata
{
    /// <summary>
    ///   <see cref="IMetadataSourceInfoWithSource" />
    /// </summary>
    public class MetadataSourceInfoWithSource : MetadataSourceInfo, IMetadataSourceInfoWithSource
    {
        #region Private

        #region - Vars

        [DebuggerBrowsable( DebuggerBrowsableState.Never )]
        private readonly MetadataSource _metadataSource;

        #endregion

        #endregion

        #region Public

        #region - Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MetadataSourceInfo" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="metadataSource">The metadata source.</param>
        public MetadataSourceInfoWithSource( string name, MetadataSource metadataSource )
            : this( name, String.Empty, metadataSource ) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="MetadataSourceInfo" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="path">The path.</param>
        /// <param name="metadataSource">The metadata source.</param>
        public MetadataSourceInfoWithSource( string name, string path, MetadataSource metadataSource )
            : base( name, path, metadataSource == null ? MappingDefinitionType.Xml : metadataSource.GetMappingDefinitionType( ) )
        {
            Guard.ArgumentNotNull( metadataSource, "metadataSource" );

            this._metadataSource = metadataSource;
        }

        #endregion

        #endregion

        #region IMetadataSourceInfoWithSource Members

        /// <summary>
        /// Gets the source.
        /// </summary>
        /// <value>
        /// The source.
        /// </value>
        public MetadataSource Source
        {
            get
            {
                return this._metadataSource;
            }
        }

        #endregion
    }
}
